package com.lbz.common;

import com.google.common.collect.Sets;

import java.util.Set;

/**
 * 常量
 *
 * @Author 林必昭
 * @Date 2019/6/14 13:42
 */
public class Constant {

    public static final String CURRENT_USER = "currentUser";

    public static final String USERNAME = "username";

    public static final String EMAIL = "email";

    public interface RedisCacheExpireTime{
        int REDIS_SESSION_EXPIRE_TIME = 60*30;  //设置session的有效期为30分钟
    }

    public interface Role{
        int ROLE_ADMIN = 0; //管理员
        int ROLE_CUSTOMER = 1;  //普通用户
    }

    public interface Cart{
        int CHECKED = 1;    //为选中状态
        int UNCHECKED = 0;  //未选中状态

        String LIMIT_NUM_FAIL= "LIMIT_NUM_FAIL";
        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_SUCCESS";
    }

    //使用set集合保存商品列表价格排序规则，price是价格字段
    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price_asc","price_desc");
    }

    public enum ProductStatusEnum{
        ON_SALE(1,"在售"),
        OFF_SALE(2,"已下架");

        private int code;
        private String value;

        ProductStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public String getValue() {
            return value;
        }
    }

    public enum OrderStatusEnum{
        //0-已取消-10-未付款，20-已付款，30-已发货，40-交易成功，50-交易关闭
        CANCELED(0,"已取消"),
        NO_PAY(10,"未支付"),
        PAID(20,"已支付"),
        SHIPPED(30,"已发货"),
        ORDER_SUCCESS(40,"订单完结"),
        ORDER_CLOSE(50,"订单由于长时间未支付或者其他原因关闭");

        private int code;
        private String value;

        public static OrderStatusEnum getByCode(int code){
            for (OrderStatusEnum orderStatusEnum:values()){
                if (orderStatusEnum.getCode()==code){
                    return orderStatusEnum;
                }
            }
            throw new RuntimeException("无法找到相应的枚举");
        }

        OrderStatusEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    //支付方式
    public enum PaymentTypeEnum{
        ONLINE_PAY(1,"在线支付"),
        ON_DELIVERY_PAY(2,"货到付款");
        private int code;
        private String value;

        PaymentTypeEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }


        /**
         * 通过传入的code找到响应的枚举，我们可以通过枚举可以获取枚举值
         * @param code
         * @return 对应的枚举
         */
        public static PaymentTypeEnum getByCode(int code){
            for (PaymentTypeEnum  paymentTypeEnum :values()){
                if (paymentTypeEnum.getCode() == code){
                    return paymentTypeEnum;
                }
            }
            throw new RuntimeException("没有找到相应的枚举");

        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    //支付平台
    public enum PayPlatformEnum{
        ALIPAY(1,"支付宝支付"),
        WEI_XIN(2,"微信支付")
        ;

        private int code;
        private String value;

        PayPlatformEnum(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    /**
     * 支付宝交易状态说明
     *
     * 至于选择enum还是interface，要看参数的类型，如果只需要返回字符串，直接使用接口来定义就行
     */
    public interface  AlipayCallback{
        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY";
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";

        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";      //大小写快捷键ctrl+shit+u

    }


}
